﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.EnterpriseLibrary.Validation;

namespace Model.Test
{
    [TestClass]
    public class UnitTestCustomerModel
    {
        [TestMethod]
        public void WhenValidatingInComplete_ResultShouldContainMessage()
        {
            Customer cut = new Customer() { };

            Validator<Customer> customerValidator = ValidationFactory.CreateValidator<Customer>("RuleSetA");
            ValidationResults results = customerValidator.Validate(cut);


            Assert.IsNotNull(results);
            Assert.IsFalse(results.IsValid);
            Assert.IsTrue(results.Count == 1);

        }


        [TestMethod]
        public void WhenValidatingToolong_ResultShouldContainMessage()
        {
            Customer cut = new Customer() { FirstName="e", LastName="12345678901" };

            Validator<Customer> customerValidator = ValidationFactory.CreateValidator<Customer>("RuleSetA");
            ValidationResults results = customerValidator.Validate(cut);


            Assert.IsNotNull(results);
            Assert.IsFalse(results.IsValid);
            Assert.IsTrue(results.Count == 1);

        }



        [TestMethod]
        public void WhenValidatingOkCustomer_ResultShouldContainNoMessage()
        {
            Customer cut = new Customer() { FirstName = "e", LastName = "1234567890" };

            Validator<Customer> customerValidator = ValidationFactory.CreateValidator<Customer>("RuleSetA");
            ValidationResults results = customerValidator.Validate(cut);


            Assert.IsNotNull(results);
            Assert.IsTrue(results.IsValid);
            Assert.IsTrue(results.Count == 0);

        }


        [TestMethod]
        public void WhenValidatingLowMarkGreaterThanHighMark_ResultShouldContainMessage()
        {
            Customer cut = new Customer() { FirstName = "e", LastName = "1234567890" , LowMark= 10, HighMark =9};

            Validator<Customer> customerValidator = ValidationFactory.CreateValidator<Customer>("RuleSetA");
            ValidationResults results = customerValidator.Validate(cut);


            Assert.IsNotNull(results);
            Assert.IsFalse(results.IsValid);
            Assert.IsTrue(results.Count == 1);

        }
    }
}
